VERSION 5.00
Begin VB.Form OfficeManagement 
   BorderStyle     =   3  'Fixed Dialog
   Caption         =   "Office management"
   ClientHeight    =   4260
   ClientLeft      =   45
   ClientTop       =   435
   ClientWidth     =   5730
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   MinButton       =   0   'False
   ScaleHeight     =   4260
   ScaleWidth      =   5730
   ShowInTaskbar   =   0   'False
   Begin VB.CommandButton Close 
      Caption         =   "Close"
      Height          =   375
      Left            =   4200
      TabIndex        =   5
      Top             =   720
      Width           =   1335
   End
   Begin VB.CommandButton Command2 
      Caption         =   "Remove"
      Height          =   375
      Left            =   0
      TabIndex        =   4
      Top             =   720
      Width           =   1215
   End
   Begin VB.CommandButton Command1 
      Caption         =   "Add"
      Height          =   375
      Left            =   1440
      TabIndex        =   3
      Top             =   720
      Width           =   1455
   End
   Begin VB.TextBox Text1 
      Height          =   375
      Left            =   1080
      TabIndex        =   1
      Top             =   240
      Width           =   3135
   End
   Begin VB.ListBox List1 
      Height          =   2985
      Left            =   0
      TabIndex        =   0
      Top             =   1200
      Width           =   4095
   End
   Begin VB.Label Label1 
      Caption         =   "Office name"
      Height          =   255
      Left            =   120
      TabIndex        =   2
      Top             =   240
      Width           =   975
   End
End
Attribute VB_Name = "OfficeManagement"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Public WhoCallMe As String
Private Sub Close_Click()
Unload Me

End Sub

Private Sub Command1_Click()
Dim sql As String
Dim rs As New ADODB.Recordset
If Trim(Text1.Text) = "" Then
    MsgBox "The Office name box can not be empty!", vbInformation + vbOKOnly, "Message"
    Exit Sub
End If
Select Case WhoCallMe
Case "IV", "TI", "BF", "ME"
    sql = "Select name from office where name ='" & UCase(Text1.Text) & "' and OS='O'"
Case Else
    sql = "Select name from office where name ='" & UCase(Text1.Text) & "' and OS='S'"
End Select
Set rs = adoConnection.Execute(sql)
If Not rs.EOF Then
    MsgBox "This name already exists"
    rs.Close
    Set rs = Nothing
    Exit Sub
End If
Select Case WhoCallMe
Case "IV", "TI", "BF", "ME"
    sql = "insert into office values('" & UCase(Text1.Text) & "','O')"
Case Else
    sql = "insert into office values('" & UCase(Text1.Text) & "','S')"
End Select
adoConnection.Execute (sql)
MsgBox "Add successfully"
rs.Close
Set rs = Nothing
List1.AddItem UCase(Text1.Text)
End Sub

Private Sub Command2_Click()
Dim sql As String

Select Case WhoCallMe
Case "IV", "TI", "BF", "ME"
    sql = "delete * from office where name='" & List1.Text & "' and OS='O'"
Case Else
    sql = "delete * from office where name='" & List1.Text & "' and OS='S'"
End Select

adoConnection.Execute (sql)
Display
End Sub

Private Sub Form_Load()
Me.Top = Screen.Height / 2 - (Me.Height / 1.5)
    Me.Left = Screen.Width / 2 - (Me.Width / 2)
Display
End Sub
Private Function Display()
Dim sql As String
Dim rs As New ADODB.Recordset
List1.Clear
Select Case WhoCallMe
Case "IV", "TI", "BF", "ME"
    sql = "Select * from office where OS='O'"
Case Else
    sql = "Select * from office where OS='S'"
End Select
Set rs = adoConnection.Execute(sql)
While Not rs.EOF
    List1.AddItem rs(0).Value
    rs.MoveNext
Wend
rs.Close
Set rs = Nothing
End Function
